<template>
  <div>
    <bbw-table
            :tableData.sync="tableData"
            @onFinish="onFinish"
            :header="header"
    >

    </bbw-table>
  </div>
</template>

<script>
    import api from '../utils/api'
    import {get, post} from '../utils/request'
export default {
    data(){
        return {
            tableData:[],
            column:[

            ],
            header:[
                {
                    label: '编号',
                    value:'id',
                    type: 'text',
                    width:55
                },
                {
                    label: '新闻标题',
                    value: 'title',

                },
                {
                    label: '作者',
                    value:'author',
                    width:200
                },
                {
                    label: '新闻内容',
                    value:'centent',
                    type: 'longtext',
                    width:200
                },

                {
                    label: '发布',
                    value:'status',
                    type:'switch',
                    width:55
                },
                {
                    label: '创建日期',
                    value:'create_time',
                    type:'text',
                    width:150
                },
                // {
                //     label: '发布日期',
                //     value:'publish_time',
                //     type:'text'
                // }

                ],
            type: 0
        }
    },
    props: {
     // msg: String
    },
    watch:{
        ['$route.query.type']:{
            handler(val){
                this.tableData = []
                let type = val
                this.type = type
                console.log(type)
                this.getData(type)
            },
            immediate: true

        }
    },
    mounted(){
        // let type = this.$route.query.type
        // this.type = type
        // // console.log(this.$route.query.type)
        // this.getData(type)
    },
    methods:{
        getData(type){
            get(api.getNews,{type}).then(res=>{
                this.tableData = res.data
            }).catch(err=>{

            })
        },
        onFinish(data){
            post(api.addNews,{
                data,
                type:this.type
            }).then(res=>{
                this.$message(res.msg)
                this.getData(this.type)
            }).catch(err=>{
                this.getData(this.type)
                this.$message(err.msg||'提交错误')
            })
        }
    }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
